package org.grow.numbertwo.service;

import com.alibaba.dubbo.config.annotation.Reference;
import com.alibaba.dubbo.config.annotation.Service;
import org.grow.zero.apis.NumberOneStockService;
import org.grow.zero.apis.NumberTwoBillService;
import org.grow.zero.dto.DealBillEntity;
import org.grow.zero.dto.StockChangeDto;

/**
 * @Author: xwg
 * @CreateDate: 21-8-18
 */

@Service
public class DealBillService implements NumberTwoBillService {
    @Override
    public String unixTime() {
        System.out.println("接受到了远程调用");
        return System.currentTimeMillis()+" :: 本服务由numberTwo dubbo容器 app提供";
    }


    @Reference
    private NumberOneStockService numberOneStockService;
    @Override
    public int insertDeal(DealBillEntity dealBillEntity) {
        System.out.println("模拟dealbill 保存进入数据库"+dealBillEntity);
//        远程调用更改库存量
        StockChangeDto stockChangeDto = new StockChangeDto();
        stockChangeDto.setQuantity(dealBillEntity.getQuantity());
        stockChangeDto.setStockCode(dealBillEntity.getStockCode());
        int i = numberOneStockService.updateStock(stockChangeDto);
        return i;

    }
}
